<template>
  <!-- 拍照上传 -->
  <div class="photoUpload">
    <p>活动规则：拍照识图</p>
    <p>生成干饭魄力值，领取专属干饭人折扣。</p>
    <!-- 上传 -->
    <!-- 预览的 -->
    <van-uploader v-model="fileList"
                  multiple
                  :max-count="1"
                  :before-read="beforeRead"
                  :after-read="afterRead" />
    <!-- 按钮的 -->
    <!-- <van-uploader v-model="fileList"
                  multiple
                  :max-count="1">
      <van-button icon="plus"
                  type="primary">上传文件</van-button>
    </van-uploader> -->
  </div>
</template>

<script>
import { uploadPictures } from '../utils/api'
export default {
  data () {
    return {
      fileList: [],
    }
  },
  methods: {
    // 上传前
    beforeRead (file) {
      // if (file.type !== 'image/jpeg') {
      //   this.$toast.fail('请上传 jpg 格式图片');
      //   return false;
      // }
      return true;
    },
    // 上传后
    async afterRead (file) {
      // // 上传中
      // file.status = 'uploading';
      // file.message = '上传中...';
      let content = file.file;
      let files = new FormData();
      files.append('file', content)
      let data = await uploadPictures(files)
      console.log(data);
      // // 上传失败
      // file.status = 'failed';
      // file.message = '上传失败';
    },
  },
}
</script>

<style lang="less" scoped>
</style>